<%-- 
    Document   : pages-body
    Created on : 17-Dec-2012, 13:11:22
    Author     : Roald
--%>
<%@page import="nl.hva.web.mvcwebapp.doa.PageDAO"%>
<%@page import="nl.hva.web.mvcwebapp.models.Page"%>
<%@page import="nl.hva.web.mvcwebapp.models.Widget"%>
<%@page import="nl.hva.web.mvcwebapp.models.PageWidget"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@include file="/WEB-INF/templates/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<h2>${pageTitle}</h2>
<hr />

<h2 id="pages">Pages</h2>
Edit a different page

<form id="pageManagement" method="post" action="pages" id="save">
    <c:choose>
        <c:when test="${allPages.size() != 0}">
            <!-- Wanneer er gebruikers opgeslagen zijn, worden ze hier getoond -->
            <select name="pages" id="pages" ONCHANGE="location = this.options[this.selectedIndex].value;">
                <c:forEach var="tempPage" items="${allPages}">
                    <option <c:if test="${requestScope.selectedPage.pageId eq tempPage.pageId}"> selected="selected" </c:if> value="?id=${tempPage.pageId}#pages" >${tempPage.pageName}</option>
                    
                </c:forEach>
            </select>
            <br />
        </c:when>
        <c:otherwise>
            There are no pages found.
        </c:otherwise>
    </c:choose>
    <br/>
    <h2>Selected page path: ${selectedPage.pagePath}</h2>
    <table class="zebra">
        <tr>
            <td><label for="pageId">Page ID</label></td>
            <td>
                ${selectedPage.pageId}
                <input hidden type="textfield" value="${selectedPage.pageId}" name="pageId">
            </td>
        </tr>
        <tr>
            <td><label for="pagePath">Page Path</label></td>
            <td>
                ${selectedPage.pagePath}
            </td>
        </tr>
        <tr>
            <td><label for="pageName">Page Title</label></td>
            <td>
                <input type="textfield" name="pageName" value="${selectedPage.pageName}"/>
            </td>
        </tr>
        <tr>
            <td><label for="pageLayout">Page Lay out</label></td>
            <td>
                <select name="pageLayout" id="pageLayout">
                    <option <c:if test="${requestScope.selectedPage.pageLayout eq '/WEB-INF/templates/sidebar-right.jsp'}"> selected="selected" </c:if> value="/WEB-INF/templates/sidebar-right.jsp">Right sidebar</option>
                    <option <c:if test="${requestScope.selectedPage.pageLayout eq '/WEB-INF/templates/sidebar-left.jsp'}"> selected="selected" </c:if> value="/WEB-INF/templates/sidebar-left.jsp">Left sidebar</option>
                    <option <c:if test="${requestScope.selectedPage.pageLayout eq '/WEB-INF/templates/full.jsp'}"> selected="selected" </c:if> value="/WEB-INF/templates/full.jsp">Full page</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><label for="pageBackground">Page Background</label></td>
            <td>
                <select name="pageBackground" id="pageBackground">
                    <option <c:if test="${requestScope.selectedPage.pageBackground eq 'chalk'}"> selected="selected" </c:if> value="chalk">Chalk</option>
                    <option <c:if test="${requestScope.selectedPage.pageBackground eq 'linen'}"> selected="selected" </c:if> value="linen">Linen</option>
                    <option <c:if test="${requestScope.selectedPage.pageBackground eq 'abstract'}"> selected="selected" </c:if> value="abstract">Abstract</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><label for="pageColor">Page Color</label></td>
            <td>
                <select name="pageColor" id="pageColor">
                    <option <c:if test="${requestScope.selectedPage.pageColor eq 'red'}"> selected="selected" </c:if> value="red">Red</option>
                    <option <c:if test="${requestScope.selectedPage.pageColor eq 'orange'}"> selected="selected" </c:if> value="orange">Orange</option>
                    <option <c:if test="${requestScope.selectedPage.pageColor eq 'green'}"> selected="selected" </c:if> value="green">Green</option>
                </select>
            </td>
        </tr>

    </table>

    <br/>
    <h2>Widgets</h2>
    <c:choose>
        <c:when test="${allWidgets.size() != 0}">
            <table class="zebra">
                <tr>
                    <th>Active</th>
                    <th>Widget name</th>
                    <th>Widget location</th>
                </tr>
                <tr>
                    <c:forEach var="tempWidget" items="${allWidgets}">
                        <!--Comparing existing widgets with relationships-->
                        <td>
                            <% int widgetlocation = -1;%> 
                            <input style="width: 20px;" type="checkbox" name="widget${tempWidget.widgetId}" value="${tempWidget.widgetId}" id="widget${tempWidget.widgetId}"
                                   <c:choose>
                                       <c:when test="${allWidgetsByPath.size() != 0}">
                                           <c:forEach var="tempWidgetByPath" items="${allWidgetsByPath}">
                                               <c:if test="${tempWidget.widgetId eq tempWidgetByPath.widgetId}">
                                                   checked 
                                               </c:if>

                                           </c:forEach>
                                           >
                                   </c:when>
                            </c:choose>
                        </td>
                        <td>
                            ${tempWidget.name}
                            <input type="hidden" name="widgetId" id="widgetId" value="${tempWidget.widgetId}"></input>
                        </td>
                        <td>
                            <select name="widgetLocation${tempWidget.widgetId}" id="widgetLocation${tempWidget.widgetId}">
                                <option value="0"                             
                                        <c:choose>
                                            <c:when test="${pwlist.size() != null}">
                                                <c:forEach var="pageWidget" items="${pwlist}">
                                                    <c:if test="${pageWidget.widget.widgetId == tempWidget.widgetId && pageWidget.page.pageId == selectedPage.pageId}">
                                                        <c:if test="${pageWidget.widgetLocation == 0}">selected="selected"</c:if>
                                                    </c:if>
                                                </c:forEach>
                                                >
                                            </c:when>
                                        </c:choose>Top Menu</option>
                                <option value="1"
                                        <c:choose>
                                            <c:when test="${pwlist.size() != null}">
                                                <c:forEach var="pageWidget" items="${pwlist}">
                                                    <c:if test="${pageWidget.widget.widgetId == tempWidget.widgetId && pageWidget.page.pageId == selectedPage.pageId}">
                                                        <c:if test="${pageWidget.widgetLocation == 1}">selected="selected"</c:if>
                                                    </c:if>
                                                </c:forEach>
                                                >
                                            </c:when>
                                        </c:choose>Content Top</option>
                                <option value="2"
                                        <c:choose>
                                            <c:when test="${pwlist.size() != null}">
                                                <c:forEach var="pageWidget" items="${pwlist}">
                                                    <c:if test="${pageWidget.widget.widgetId == tempWidget.widgetId && pageWidget.page.pageId == selectedPage.pageId}">
                                                        <c:if test="${pageWidget.widgetLocation == 2}">selected="selected"</c:if>
                                                    </c:if>
                                                </c:forEach>
                                                >
                                            </c:when>
                                        </c:choose>Sidebar</option>
                                <option value="3"
                                        <c:choose>
                                            <c:when test="${pwlist.size() != null}">
                                                <c:forEach var="pageWidget" items="${pwlist}">
                                                    <c:if test="${pageWidget.widget.widgetId == tempWidget.widgetId && pageWidget.page.pageId == selectedPage.pageId}">
                                                        <c:if test="${pageWidget.widgetLocation == 3}">selected="selected"</c:if>
                                                    </c:if>
                                                </c:forEach>
                                                >
                                            </c:when>
                                        </c:choose>Content Bottom</option>
                                <option value="4"
                                        <c:choose>
                                            <c:when test="${pwlist.size() != null}">
                                                <c:forEach var="pageWidget" items="${pwlist}">
                                                    <c:if test="${pageWidget.widget.widgetId == tempWidget.widgetId && pageWidget.page.pageId == selectedPage.pageId}">
                                                        <c:if test="${pageWidget.widgetLocation == 4}">selected="selected"</c:if>
                                                    </c:if>
                                                </c:forEach>
                                                >
                                            </c:when>
                                        </c:choose>Footer</option>
                            </select>
                        </td>
                    </tr>
                </c:forEach>

            </table>
        </c:when>
        <c:otherwise>
            <!-- Als er geen gebruikers zijn, wordt deze melding getoond -->
            There are no widgets found.
        </c:otherwise>
    </c:choose>

    <div style="position: fixed; bottom: 10px; right: 10px; display: block; padding: 10px; background: white; box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);">
        <input style="padding: 5px; height: 40px;" type="submit" value="Save Changes" class="submit button">
    </div>
</form>